<template>
	<page-body>
		<view class="page">

			<!---flex布局flex布局开始-->
			<view class="flex flex-direction align-stretch benben-flex-layout">
				<view>
					<benben-flex-tabs class-name='benbenTabsfd1_0_ibhf' v-model="tab" ref="benben_tabsfd1_0"
						select-mark="benben_tabsfd1_0" key="benben_tabsfd1_0" :open-title-type='false'
						:open-sticky='true' :top='0' :is-show-content='false' :scrollspy='false'
						:tabs-info.sync="tabsInfofd1_0">

						<scroll-view @scroll="tabsInfofd1_0.scrollX = $event.detail.scrollLeft" id="benben_tabsfd1_0"
							class="benben-tabs" style="width:750rpx" :scroll-x="true" :scroll-left="tabsInfofd1_0.moveX"
							scroll-with-animation="all .3s ease" :show-scrollbar='false' :enhanced="true">
							<view class="benben-tabs-content" id="benben_tabsfd1_0-content">
								<view id="benben_tabsfd1_0-title"
									class="benben-tabs-title flex flex align-center justify-around">
									<view
										:class="{ 'checkTitlefd1_0_ibhf': tab == '1', 'flex flex-wrap align-center': true }"
										@tap="getlist(1)" :id="`benben_tabsfd1_0-title-item-${'1'}`">

										<text>学习资源</text>

									</view>
									<view
										:class="{ 'checkTitlefd1_0_ibhf': tab == '2', 'flex flex-wrap align-center': true }"
										@tap="getlist((2))" :id="`benben_tabsfd1_0-title-item-${'2'}`">

										<text>练习题库</text>

									</view>
								</view>
								<view :style="{ left: tabsInfofd1_0.lineleft, maxWidth: tabsInfofd1_0.lineWidth ,}"
									id="benben_tabsfd1_0-line"
									class="benben-tabs-line flex benben-flex-tabs-line linefd1_0_ibhf"
									:class="{'benben-tabs-line-active':tabsInfofd1_0.isInit}"></view>
							</view>
						</scroll-view>

					</benben-flex-tabs>

				</view>
			</view>

			<!---flex布局flex布局结束-->
			<view class='flex flex-direction flex-wrap align-stretch' style="margin-top: 10rpx;">
				<template v-if="tab==1">
					<view class="" v-if="datum.length > 0 && isup" v-for='(item,key0) in datum'>
						<!--mp4  -->
						<view class='flex flex-wrap align-center justify-between instructioning_fd2_5_c0'
							v-if="item.file_type==2" :key='key0'>
							<view class='flex flex-wrap align-center'>
								<image class='instructioning_fd2_5_c0_c0_c0' mode="aspectFit"
									:src='STATIC_URL+"k1.png"'>
								</image>
								<text class='instructioning_fd2_5_c0_c0_c1'>{{item.resource_name}}</text>
							</view>
							<button class='instructioning_fd2_5_c0_c1'
								@tap="seePdf(item.file_path,item.aid)">{{$t('查看')}}</button>
						</view>
						<view class='flex flex-wrap align-center justify-between instructioning_fd2_5_c0'
							v-else :key='key0'>
							<view class='flex flex-wrap align-center'>
								<!-- item.file_type =  hz=='png'?1:hz=='xlsx'?3:hz == 'mp4' ? 2 : hz == 'pdf' ? 4 : hz == 'ppt' ? 5 : hz == 'docx' ?6 : hz == 'mp3' ?7:'' -->
								<image class='instructioning_fd2_5_c0_c0_c0' mode="aspectFit" :src='item.file_type==1?STATIC_URL+"png.png":item.file_type==3?STATIC_URL+"bg.png":item.file_type==4?STATIC_URL+"pdf.png":item.file_type==5?STATIC_URL+"ppt.png":item.file_type==6?STATIC_URL+"word.png":STATIC_URL+"word.png"'>
								</image>
								<text class='instructioning_fd2_5_c0_c0_c1'>{{item.resource_name}}</text>
								<!-- .{{item.fileType}} -->
							</view>
							<button class='instructioning_fd2_5_c0_c1'
								@tap="seePdf(item.resource_file_path,item.resource_id,item)">{{$t('查看')}}</button>
						</view>

						<!-- pdf -->
						<!-- <view class='flex flex-wrap align-center justify-between instructioning_fd2_5_c0'
							v-if="item.file_type==5" :key='key0'>
							<view class='flex flex-wrap align-center'>
								<image class='instructioning_fd2_5_c0_c0_c0' mode="aspectFit"
									:src='STATIC_URL+"k2.png"'>
								</image>
								<text class='instructioning_fd2_5_c0_c0_c1'>{{item.resource_name}}.pdf</text>
							</view>
							<button class='instructioning_fd2_5_c0_c1'
								@tap="seePdf(item.file_path,item.aid)">{{$t('查看')}}</button>
						</view> -->

						<!-- ppt -->
						<!-- <view class='flex flex-wrap align-center justify-between instructioning_fd2_5_c0'
							v-if="item.file_type==4" :key='key0'>
							<view class='flex flex-wrap align-center'>
								<image class='instructioning_fd2_5_c0_c0_c0' mode="aspectFit"
									:src='STATIC_URL+"k3.png"'>
								</image>
								<text class='instructioning_fd2_5_c2_c0_c1'>{{item.resource_name}}.ppt</text>
							</view>
							<button class='instructioning_fd2_5_c0_c1'
								@tap="seePdf(item.file_path,item.aid)">{{$t('查看')}}</button>
						</view> -->

						<!-- 文档 -->
					<!-- 	<view class='flex flex-wrap align-center justify-between instructioning_fd2_5_c0'
							v-if="item.file_type==7" :key='key0'>
							<view class='flex flex-wrap align-center'>
								<image class='instructioning_fd2_5_c0_c0_c0' mode="aspectFit"
									:src='STATIC_URL+"k4.png"'>
								</image>
								<text class='instructioning_fd2_5_c2_c0_c1'>{{item.resource_name}}.doc</text>
							</view>
							<button class='instructioning_fd2_5_c0_c1'
								@tap="seePdf(item.file_path,item.aid)">{{$t('查看')}}</button>
						</view> -->

						<!-- 图片 -->
						<!-- <view class='flex flex-wrap align-center justify-between instructioning_fd2_5_c0'
							v-if="item.file_type==1" :key='key0'>
							<view class='flex flex-wrap align-center'>
								<image class='instructioning_fd2_5_c0_c0_c0' mode="aspectFit"
									:src='STATIC_URL+"k5.png"'>
								</image>
								<text class='instructioning_fd2_5_c0_c0_c1'>{{item.resource_name}}.png</text>
							</view>
							<button class='instructioning_fd2_5_c0_c1'
								@tap="seePdf(item.file_path,item.aid)">{{$t('查看')}}</button>
						</view> -->
					</view>
					<view v-if="datum.length==0 && isup">
						<slot>
							<view class="public-page-empty">
								<image src='/static/global/order.png'></image>
								<view class="txt">暂无数据</view>
							</view>
						</slot>
					</view>
				</template>

				<view class="" v-if="tab==2">
					<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout list_flex_2_ibhf">
						<view class='flex flex-direction flex-wrap align-stretch list_fd2_0_ibhf'
							v-for="(iten, index) in list" :key='index' v-if="list.length>0 && isup">
							<view class='flex flex-wrap align-center list_fd2_0_c0_ibhf'>
								<text>1</text>
								<view class='flex flex-wrap align-center list_fd2_0_c0_c1_ibhf'>
									<text class='list_fd2_0_c0_c1_c0_ibhf'>{{iten.question_type_name}}</text>
								</view>
							</view>
							<view class='flex flex-wrap align-center'>
								<text>{{iten.question_title}}</text>
							</view>
						</view>
						<view v-if="list.length==0 && isup">
							<slot>
								<view class="public-page-empty">
									<image src='/static/global/order.png'></image>
									<view class="txt">暂无数据</view>
								</view>
							</slot>
						</view>
					</view>
				</view>
			</view>
			<!-- <view v-if="tab==2" class="flex flex-direction flex-wrap align-center justify-center benben-position-layout flex list_flex_3_ibhf">
				<button class='list_fd3_0_ibhf'>下一节</button>

			</view>
			<view :style="{height: '88rpx'}"></view> -->

		</view>
	</page-body>
</template>
<script>
	import filePreview from '@/common/utils/filePreview.js'
	export default {
		mixins: [filePreview],
		components: {},


		data() {
			return {
				id: '',
				"tabsInfofd1_0": {
					lineleft: '',
					lineWidth: '',
					moveX: 0,
					scrollX: 0,
					PageScrollX: 0,
					isInit: false
				},
				"tab": "1",
				"list": [],
				datum: [],
				lessonplanning_id: '210',
				isup: false,
			};
		},
		computed: {

		},
		watch: {},
		onLoad(options) {
			this.id = options.id
			if (global.appTabBarType) this.toHomeDiy()
			this.getlist(1)
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {

		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			jump(item, index) {
				if (this.tab == 1) {
					uni.navigateTo({
						url: "/pages/kc/kqyxzsd/kqyxzsd?type=2"
					})
				} else {
					uni.navigateTo({
						url: "/pages/kc/examinationRes/examinationRes?type=2"
					})
				}

			},
			//备课管理-获取课件列表
			async getlist(type) {
				this.isup = false
				this.tab = type
				//请求方法
				//数据验证
				let url = ''
				if (type == 1) {
					url = global.apiUrls.post68cbcfecd48f6
				} else {
					url = global.apiUrls.post68cd059eed5de
				}

				let datadatum = await this.$api.get(url, {
					textbookchapter_id: this.id,
				});

				if (datadatum.data.code != 1) {
					this.$message.info(datadatum.data.msg);
					return
				}
				let infodatum = datadatum.data;
				this.isup = true
				if (type == 1) {
					this.datum = infodatum.data.map(item => {
						item.fileType = item.resource_file_path.slice(item.resource_file_path.lastIndexOf('.'))
						let hz = item.fileType.split('.')[1]
						item.fileType=hz
						item.file_type =  hz=='png'?1:hz=='xlsx'?3:hz == 'mp4' ? 2 : hz == 'pdf' ? 4 : hz == 'ppt' ? 5 : hz == 'docx' ?6 : hz == 'mp3' ?7 : hz == 'pptx' ?5:''
						return item
						// item.file_type = hz == 'mp4' ? 2 : hz == 'pdf' ? 5 : hz == 'ppt' ? 4 : hz == 'doc' ? 7 : hz == 'png' ? 1:hz == 'pptx' ? 4  : ''
						// return item
					})
					console.log(this.datum)
				} else {
					this.list = infodatum.data
				}


			},
			seePdf(file, aid, item) {
				console.log('vvvvvvvvvvvvvv', item);
				let _this = this;
				let id = aid;
				let url = file;
				if(item.file_type==2){
						this.mixinToPlayVideo(item.resource_file_path)
					// if(this.type==2){
					// 	this.mixinToPlayVideo(item.resource_file_path)
					// 	return
					// }
					// let rate=this.type==1?item.rate:item.progress
					// uni.navigateTo({
					// 	url: `/pages/course/scourseStudy/scourseStudy?url=${item.resource_file_path}&file_type=${item.file_type}&aid=${item.resource_id}&rate=${rate}`
					// })
				}else{
						let name=item.resource_name
					this.previewFile(item.resource_file_path, name)
					// let res = await this.$api.post(global.apiUrls.post68d8f2b91ed54, {
					// 	resource_id: item.resource_id,
					// 	progress: 100
					// })
					// 	// let name=item.resource_name+'.'+item.fileType
					// 	let name=item.resource_name
					// this.previewFile(item.resource_file_path, name)
					// if(this.type==1){
					// 	this.getim68f99801dcf8Func()
					// }else{
					// 	this.getlist()
					// }
				}
				
				return
				// #ifdef APP-PLUS

				let files = uni.getStorageSync('files') ? JSON.parse(uni.getStorageSync('files')) : {}
				console.log(files)
				if (files[id]) {
					plus.runtime.openFile(files[id], {}, (res) => {
						console.log("res=>", res);
					})
				} else {
					downloadFile()
				}

				function downloadFile() {
					uni.showLoading({
						title: '加载中'
					})
					const dtask = plus.downloader.createDownload(url, {}, function(d, status) {
						if (status == 200) {
							console.log('保存成功')
							uni.hideLoading();
							files[id] = d.filename
							uni.setStorageSync('files', JSON.stringify(files))
							plus.runtime.openFile(d.filename)
						} else {
							plus.downloader.clear()
							uni.hideLoading();
							uni.showToast({
								title: '文档加载失败，请稍后再试',
								icon: 'none',
							})
						}
					})
					dtask.start()
				}
				// #endif

				// #ifdef H5
				window.open(url)
				// #endif
			},

		}
	};
</script>
<style lang="scss" scoped>
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: rgba(255, 255, 255, 1);
		background-size: 100% auto;

		.checkTitlefd1_0_ibhf {
			font-weight: 700 !important;
			font-size: 28rpx !important;
			color: #333 !important;
			background-color: rgba(255, 255, 255, 1) !important;
		}

		.linefd1_0_ibhf {
			width: 40rpx;
			height: 8rpx;
			top: 80rpx;
			background: #145efd;
			background-size: 100% auto !important;
			border-radius: 4rpx;
		}

		.fd1_1_ibhf {
			padding: 0rpx 24rpx 0rpx 24rpx;
		}

		.fd1_1_c0_ibhf {
			border-bottom: 1px solid #eee;
			padding: 24rpx 0rpx 24rpx 0rpx;
		}

		.fd1_1_c0_c0_c0_ibhf {
			font-size: 32rpx;
			margin: 0rpx 0rpx 24rpx 0rpx;
		}

		.fd1_1_c0_c0_c1_ibhf {
			font-size: 24rpx;
		}

		.flex_0_ibhf {
			width: 750rpx;
			height: 88rpx;
			overflow: hidden;
			z-index: 10;
			top: 0rpx;
			background: #fff;
			background-size: 100% auto !important;

			.fd0_0_ibhf {
				padding: 0rpx 32rpx 0rpx 32rpx;

				.fd0_0_c1_c0_ibhf {
					font-size: 36rpx;
					font-weight: 700;
					color: #333333;
					line-height: 50rpx;
				}
			}
		}

		.fd0_0_c0_ibhf {
			width: 120rpx;

			.fd0_0_c0_c0_ibhf {
				font-size: 36rpx;
				color: #333;
			}
		}
	}

	::v-deep .benbenTabsfd1_0_ibhf {
		width: 750rpx;
		height: 90rpx;
		white-space: nowrap;
		background: #fff;
		text-align: center;
	}

	.instructioning_fd2_5_c0_c1 {
		background: rgba(20, 94, 253, .1);
		border-radius: 33rpx 33rpx 33rpx 33rpx;
		width: 96rpx;
		line-height: 48rpx;
		font-size: 24rpx;
		color: rgba(20, 94, 253, 1);
	}

	.instructioning_fd2_5_c0_c0_c1 {
		color: #333;
		font-size: 28rpx;
		font-weight: 500;
		line-height: 40rpx;
		width: 430rpx;
		-webkit-line-clamp: 1;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
	}

	.instructioning_fd2_5_c0_c0_c0 {
		width: 40rpx;
		height: 40rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		margin: 0rpx 016rpx 0rpx 0rpx;
	}

	.instructioning_fd2_5_c0 {
		background: #FFFFFF;
		padding: 32rpx 24rpx 024rpx 24rpx;
		margin: 0rpx 24rpx 24rpx 24rpx;
		border-radius: 32rpx;
		background-size: 100% auto;
		height: 104rpx;
		border-bottom: 2rpx solid #F2F4F7;
	}

	.list_flex_2_ibhf {
		padding: 24rpx;

		.list_fd2_0_ibhf {
			padding: 24rpx;
			border-bottom: 1px solid #eee;

			.list_fd2_0_c0_ibhf {
				margin: 0rpx 0rpx 12rpx 0rpx;

				.list_fd2_0_c0_c1_ibhf {
					background: #5695F7;
					height: 40rpx;
					border-radius: 8rpx;
					padding: 0rpx 10rpx 0rpx 10rpx;
					margin: 0rpx 0rpx 0rpx 20rpx;

					.list_fd2_0_c0_c1_c0_ibhf {
						color: var(--benbenFontColor3);
						font-size: 24rpx;
						line-height: 40rpx;
					}
				}
			}
		}
	}

	.list_flex_3_ibhf {
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		bottom: calc(88rpx + var(--window-bottom));

		.list_fd3_0_ibhf {
			border-radius: 12rpx;
			width: 702rpx;
			line-height: 84rpx;
			font-size: 24rpx;
			background: #145EFD;
			color: #fff;
			height: 84rpx;
		}
	}

	.public-page-empty {
		display: flex;
		justify-content: center;
		flex-direction: column;
		align-items: center;
		padding: 120upx 0 0 0;

		image {
			width: 300rpx;
			height: 300rpx;
		}

		.txt {
			font-size: 28upx;
			color: $uni-text-color;
			text-align: center;
			line-height: 100upx;
			color: var(--benben-loading-color, #999999);
		}

		.loadTips {
			line-height: 30upx;
		}

		.btn {
			width: 260upx;
			height: 78upx;
			line-height: 78upx;
			background: linear-gradient(309deg, rgba(254, 49, 0, 1) 0%, rgba(255, 90, 16, 1) 100%);
			opacity: 1;
			border-radius: 44upx;
			font-size: 28upx;
			color: #fff;
			text-align: center;
			margin-top: 100upx;
		}
	}
</style>
